   /**
         * FileReader共有4种读取方法：
         * 1.readAsArrayBuffer(file)：将文件读取为ArrayBuffer。
         * 2.readAsBinaryString(file)：将文件读取为二进制字符串
         * 3.readAsDataURL(file)：将文件读取为Data URL
         * 4.readAsText(file, [encoding])：将文件读取为文本，encoding缺省值为'UTF-8'
         */
        var wb;//读取完成的数据
        var rABS = false; //是否将文件读取为二进制字符串
 
        //开始导入
        function importf(obj) {
            if(!obj.files) {
                return;
            }
            var f = obj.files[0];
            var reader = new FileReader();
            reader.onload = function(e) {
                var data = e.target.result;
                if(rABS) {
                    wb = XLSX.read(btoa(fixdata(data)), {//手动转化
                        type: 'base64'
                    });
                } else {
                    wb = XLSX.read(data, {
                        type: 'binary'
                    });
                }
                /**
                 * wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
                 * wb.Sheets[Sheet名]获取第一个Sheet的数据
                 */
                var excelJson = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
                // document.getElementById("excelContent").innerHTML= JSON.stringify( excelJson );
                //生成表格数据
                let tbody = document.querySelector('tbody')
                // let tmain = JSON.stringify(excelJson); 
                console.log(tbody)
                console.log(excelJson)
                var excelarr = [];
                btnsave.onclick = function(){
                    console.log(1)
                }
                excelJson.forEach(v=>{
                   
                   var showtbody =`
                    <tr class="odd gradeX">
                        <td>${v['姓名']}</td>
                        <td>${v['性别']}</td>
                        <td>${v['来源']}</td>
                        <td class="center">${v['身份证']}</td>
                        <td class="center">${v['地址']}</td>
                        <td class="center">${v['手机号']}</td>
                        <td class="center">${v['QQ']}</td>
                        <td class="center">${v['业务类型']}</td>
                        <td class="center">${v['入学时间']}</td>
                        <td class="center">
                        <!-- <button type="button" class="btn btn-success">编辑</button> -->
                    <button type="button" class="btn btn-primary btn-sm btn-success  addmessage"
        data-toggle="modal" data-target="#myModal">
        编辑
    </button>
    <button type="button" class="btn btn-danger btn-sm">删除</button>
                    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog"aria-labelledby="myModalLabel">   
                    </div>
                        </td>
                    </tr>
                    
                    `
                    excelarr.push(showtbody)
                    console.log(excelarr)
                     //翻页



var nums = 5; //每页出现的数量
var pages = Math.ceil(excelarr.length/nums); //得到总页数

var thisDate = function(curr){
    //此处只是演示，实际场景通常是返回已经当前页已经分组好的数据
    var str = '', last = curr*nums - 1;
    last = last >= excelarr.length ? (excelarr.length-1) : last;
    for(var i = (curr*nums - nums); i <= last; i++){
        str +=  excelarr[i] ;
    }
    return str;
};

//调用分页
laypage({
    cont: 'biuuu_city',
    pages: pages,
    jump: function(obj){
        document.getElementById('biuuu_city_list').innerHTML = thisDate(obj.curr);
    }
})
                   
                })
                



            };
            if(rABS) {
                reader.readAsArrayBuffer(f);
            } else {
                reader.readAsBinaryString(f);
            }
        }
 
        //文件流转BinaryString
        function fixdata(data) { 
            var o = "",
                l = 0,
                w = 10240;
            for(; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
            o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
            return o;
        }

       




//获取动态创建属性
// $(document).on('click','#btnsave',function(){
//     console.log($('#iptname').val())    
// })
$('#btnsave').click(function(){
    console.log($("#iptname").val())
    axios.get(addgoodsApi,{
        params:{
            pname:$("#iptname").val(),
            pimg:$("#iptid").val(),
            pdesc:$("#province").val()+$('#city').val()+$('#town').val()
        }
    }).then(sel=>{
        console.log(sel)
        axios.get(goodslistApi,{
            parmas:{
                pid:$("#iptid").val()
            }
        }).then(res=>{
            console.log(res.data.data)
          
            let idData = document.querySelector('.idData');
          
                let trdata= `
            <tr class="odd gradeX">
            <td>${res.data.data[0].pname}</td>
            <td></td>
            <td>Win 95+</td>
            <td class="center">${res.data.data[0].pimg}</td>
            <td class="center">${res.data.data[0].pdesc}</td>
            <td class="center">4</td>
            <td class="center">X</td>
            <td class="center">X</td>
            <td class="center">X</td>
            <td class="center">
                    <!-- <button type="button" class="btn btn-success">编辑</button> -->
                    <button type="button" class="btn btn-primary btn-sm btn-success  addmessage"
        data-toggle="modal" data-target="#myModal">
        编辑
    </button>
    <button type="button" class="btn btn-danger btn-sm">删除</button>
                    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog"aria-labelledby="myModalLabel">   
                    </div>                                
                    
            </td>
        </tr>

            `
            idData.innerHTML += trdata;
            excelarr.push(trdata);
            
        })
    })

})
//编辑按钮动态生成模态框
$('#myModal1').html(
    `<div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal"
                                                                    aria-label="Close"><span
                                                                        aria-hidden="true">&times;</span></button>
                                                                <h4 class="modal-title" id="myModalLabel">编辑学员信息</h4>
                                                            </div>
                                                            <div class="modal-body">
                                                                       
                                                                        <form class="form-inline">
                                                                            <div class="form-group">
                                                                            <label for="iptname">姓名</label>
                                                                            <input type="text"   class="iptname form-control">
                                                                        </div>
                                                                     
                                                                        <div class="form-group">
                                                                            <label for="iptsex">性别</label>
                                                                            <input type="text"  id="iptsex" class="form-control" style="width:50px">
                                                                        </div>
                                                                        <div class="form-group">
                                                                                <label for="iptfrom">来源</label>
                                                                                <input type="text"  id="iptfrom" class="form-control">
                                                                            </div>
        
                                                                            <div class="form-group">
                                                                                    <label for="iptid" class="wz">身份证</label>
                                                                                    <input type="text"  id="iptid" class="form-control">
                                                                                </div>
                                                                                
                                                                                <div class="outer form-group">
                                                                                        <label for="province">地址</label>
                                                                                        <input type="text"  id="province" class="form-control" style="width:270px">
                                                                                    </div>
                                                                                <div class="form-group">
                                                                                        <label for="iphone">手机号</label>
                                                                                        <input type="text"  id="iphone" class="form-control" style="margin-right:50px;width:170px">
                                                                                    </div>
                                                                                    <div class="form-group">
                                                                                            <label for="weixin">微信</label>
                                                                                            <input type="text"  id="weixin" class="form-control">
                                                                                        </div>
                                                                                        <div class="form-group">
                                                                                                <label for="stype">业务类型</label>
                                                                                                <input type="text"  id="stype" class="form-control">
                                                                                            </div>
                                                                                    <div class="form-group">
                                                                                            <label for="scome">入学时间</label>
                                                                                            <input type="text"  id="scome" class="form-control">
                                                                                        </div>         
                                                                        </form>
                                                            </div>
                                                            <div class="modal-footer">
                                                                    <button type="button" class="btn btn-primary " data-dismiss="modal" id="btnsave">保存</button>
                                                                <button type="button" class="btn btn-default"
                                                                    data-dismiss="modal">取消</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>`


)
// $(document).on("click",".addmessage",function(){
   
//      let trs = $(this).parent().parent();
//     console.log($(trs).html())
   
    
// })
let trs = document.querySelectorAll('tr');
console.log(trs)
for(var i = 0; i<trs.length;i++){
    trs[i].setAttribute('dataid',i)
}
let btns = document.querySelectorAll('#myModal1');
for(let i = 0; i<btns.length;i++){
    btns[i].setAttribute('dataid',i+1)
}
let bianjis = document.querySelectorAll('.addmessage');

for( let i = 0; i< bianjis.length;i++){
    console.log(i)
    bianjis[i].setAttribute('dataid',i)
     bianjis[i].addEventListener('click',function(){
                 let tds =this.parentNode;
                 let trss = tds.parentNode;
                 let forms =this.nextElementSibling
                 console.log(forms)    
       forms.querySelector('.iptname').value = trss.querySelectorAll('td')[0].innerHTML
       forms.querySelector('#iptsex').value = trss.querySelectorAll('td')[1].innerHTML
        forms.querySelector('#iptfrom').value = trss.querySelectorAll('td')[2].innerHTML
       forms.querySelector('#iptid').value = trss.querySelectorAll('td')[3].innerHTML
         forms.querySelector('#province').value = trss.querySelectorAll('td')[4].innerHTML
         forms.querySelector('#iphone').value = trss.querySelectorAll('td')[5].innerHTML
         forms.querySelector('#weixin').value = trss.querySelectorAll('td')[6].innerHTML
        forms.querySelector('#stype').value = trss.querySelectorAll('td')[7].innerHTML
         forms.querySelector('#scome').value = trss.querySelectorAll('td')[8].innerHTML
 
})

}



